from charalize import *


def banchmark():
    a = Charalize()
    from time import time
    try:
        img = Image.open('origin.jpg')
    except:
        print('Benchmark initiation failed.')
        return None
    print('Single thread transformation benchmark procedure initiated.')
    start = time()
    itors = 500
    for i in range(itors):
        a.transform_L(img)
        print('Progress: {} of {}'.format(i, itors), end='\r', flush=True)
    print('{} iteration of transformation done.\nFPS: {:.5f} @ {}x{} Resolution'.format(
        itors,  itors / (time() - start),img.size[0],img.size[1]))


if __name__ == "__main__":
    import cProfile
    print('=' * 90,
          '\n{:^90}\n'.format('Benchmark Test'),
          '-' * 90, sep='')
    cProfile.run('banchmark()', 'result.o')
    import pstats
    print('=' * 90,
          '\n{:^90}\n'.format('cProfile Analysis'),
          '-' * 90, sep='')
    p = pstats.Stats('result.o')
    p.sort_stats('time').print_stats(20)
    print('=' * 90)
